package user

import (
	"day12_12_homework/internal/api/request"
	"day12_12_homework/internal/models/service"
	"github.com/gin-gonic/gin"
	"net/http"
	"strconv"
)

func RealName(c *gin.Context) {
	var json request.RealNameRequest
	if err := c.ShouldBindJSON(&json); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
		return
	}
	value, _ := c.Get("userId")
	id := value.(string)
	myId, _ := strconv.Atoi(id)

	name, s := service.RealName(myId, json.RealNames, json.IdCard)
	if s != "" {
		c.JSON(http.StatusBadRequest, gin.H{
			"message": s,
		})
		return
	}

	c.JSON(http.StatusOK, gin.H{
		"message": "实名成功",
		"data":    name,
	})

}
